package com.liu.reflection;

public class CreateClassInstance {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {

        Person person = new Student();
        Class c1 = person.getClass();

        Class c2 = Class.forName("com.liu.reflection.Student");

        Class<Student> c3 = Student.class;

        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c3.hashCode());

        Class superclass = c1.getSuperclass();
        Object o = superclass.newInstance();
        System.out.println(o.hashCode());

    }
}

class Person{
    public String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person{
    public Student() {
        this.name = "学生";
    }
}

class Teacher extends Person{
    public Teacher() {
        this.name = "老师";
    }
}
